from django.contrib import admin
from django import forms

from preDepositLogs.models import PreDepositLog
from .manager import PreDepositLogManage


class PreDepositLogCreationForm(forms.ModelForm):
    class Meta:
        model = PreDepositLog
        fields = ('operationMoney', 'user')

    def save(self, commit=True):
        print("asd")
        validated_data = {'user': self.cleaned_data.get("user"), 'operationMoney': self.cleaned_data.get("operationMoney")}
        preDepositLog = PreDepositLogManage().create(**validated_data)
        print(preDepositLog)
        if preDepositLog:
            return preDepositLog


@admin.register(PreDepositLog)
class PreDepositLogAdmin(admin.ModelAdmin):
    list_display = ('user', 'operationMoney')
    list_display_links = None

    # form = UserChangeForm
    add_form = PreDepositLogCreationForm

    fieldsets = (
        (None, {'fields': ('user', 'operationMoney',)}),
    )
    add_fieldsets = (
        (None, {
            'classes': ('wide',),
            'fields': ('user', 'operationMoney',)}
         ),
    )
    search_fields = ('user__name', 'user__phoneNumber')
    ordering = ('-createdAt',)